'''
Image Classification Main Programme
By BrokenData
MIT License
'''

import tensorflow as tf
from tensorflow.keras.layers import *
from PIL import Image
import numpy as np
from tensorflow.python.ops.gen_logging_ops import image_summary

class BasicImageClassification(object):
    def __init__(self,Resolution) -> None:
        super().__init__()
        self.TFSeq=tf.keras.Sequential()
        self.TrainData=None
        self.Resolution=Resolution
    def FeedTrainDatabase(self,TrainGroup):
        self.TrainData=TrainGroup
    def BuildUp(self):
        self.TFSeq.add(Flatten(input_shape=self.Resolution))
        self.TFSeq.add(Dense(256,activation='tanh'))
        self.TFSeq.add(Dropout(0.2))
        self.TFSeq.add(Dense(64,activation='relu'))
        self.TFSeq.add(Dense(self.TrainData.KindLen))
        self.TFSeq.compile(optimizer='adam',loss='mse',metrics=['accuracy'])
        self.TFSeq.summary()
    def Train(self,epochs=10):
        Given=self.TrainData.GiveTrainData()
        self.TFSeq.fit(Given[0],Given[1],epochs=epochs)
    def Predict(self,ImagePointer):
        PredictData=np.asarray(ImagePointer.resize((self.Resolution[0],self.Resolution[1])))
        self.TFSeq.predict([PredictData])
    def PredictFile(self,ImagePath):
        im=Image.open(ImagePath)
        self.Predict(im)
